/*
 * Copyright (c) 2024 vitasystems GmbH
 *
 * This file is part of project EHRbase Migration Tool
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ehrbase.migration.importer.v4.jooq.pg.tables;

import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import org.ehrbase.migration.importer.v4.jooq.pg.Indexes;
import org.ehrbase.migration.importer.v4.jooq.pg.Keys;
import org.ehrbase.migration.importer.v4.jooq.pg.tables.records.TemplateStoreRecord;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Function4;
import org.jooq.Index;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Records;
import org.jooq.Row4;
import org.jooq.Schema;
import org.jooq.SelectField;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions;
import org.jooq.UniqueKey;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({"all", "unchecked", "rawtypes", "this-escape"})
public class TemplateStore extends TableImpl<TemplateStoreRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of <code>ehr.template_store</code>
     */
    public static final TemplateStore TEMPLATE_STORE = new TemplateStore();

    /**
     * The class holding records for this type
     */
    @Override
    public Class<TemplateStoreRecord> getRecordType() {
        return TemplateStoreRecord.class;
    }

    /**
     * The column <code>ehr.template_store.id</code>.
     */
    public final TableField<TemplateStoreRecord, UUID> ID =
            createField(DSL.name("id"), SQLDataType.UUID.nullable(false), this, "");

    /**
     * The column <code>ehr.template_store.template_id</code>.
     */
    public final TableField<TemplateStoreRecord, String> TEMPLATE_ID =
            createField(DSL.name("template_id"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.template_store.content</code>.
     */
    public final TableField<TemplateStoreRecord, String> CONTENT =
            createField(DSL.name("content"), SQLDataType.CLOB, this, "");

    /**
     * The column <code>ehr.template_store.creation_time</code>.
     */
    public final TableField<TemplateStoreRecord, OffsetDateTime> CREATION_TIME = createField(
            DSL.name("creation_time"), SQLDataType.TIMESTAMPWITHTIMEZONE(6).nullable(false), this, "");

    private TemplateStore(Name alias, Table<TemplateStoreRecord> aliased) {
        this(alias, aliased, null);
    }

    private TemplateStore(Name alias, Table<TemplateStoreRecord> aliased, Field<?>[] parameters) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table());
    }

    /**
     * Create an aliased <code>ehr.template_store</code> table reference
     */
    public TemplateStore(String alias) {
        this(DSL.name(alias), TEMPLATE_STORE);
    }

    /**
     * Create an aliased <code>ehr.template_store</code> table reference
     */
    public TemplateStore(Name alias) {
        this(alias, TEMPLATE_STORE);
    }

    /**
     * Create a <code>ehr.template_store</code> table reference
     */
    public TemplateStore() {
        this(DSL.name("template_store"), null);
    }

    public <O extends Record> TemplateStore(Table<O> child, ForeignKey<O, TemplateStoreRecord> key) {
        super(child, key, TEMPLATE_STORE);
    }

    @Override
    public Schema getSchema() {
        return aliased() ? null : org.ehrbase.migration.importer.v4.jooq.pg.Ehr.EHR;
    }

    @Override
    public List<Index> getIndexes() {
        return Arrays.asList(Indexes.TEMPLATE_STORE_ID_UNQ);
    }

    @Override
    public UniqueKey<TemplateStoreRecord> getPrimaryKey() {
        return Keys.TEMPLATE_STORE_PKEY;
    }

    @Override
    public TemplateStore as(String alias) {
        return new TemplateStore(DSL.name(alias), this);
    }

    @Override
    public TemplateStore as(Name alias) {
        return new TemplateStore(alias, this);
    }

    @Override
    public TemplateStore as(Table<?> alias) {
        return new TemplateStore(alias.getQualifiedName(), this);
    }

    /**
     * Rename this table
     */
    @Override
    public TemplateStore rename(String name) {
        return new TemplateStore(DSL.name(name), null);
    }

    /**
     * Rename this table
     */
    @Override
    public TemplateStore rename(Name name) {
        return new TemplateStore(name, null);
    }

    /**
     * Rename this table
     */
    @Override
    public TemplateStore rename(Table<?> name) {
        return new TemplateStore(name.getQualifiedName(), null);
    }

    // -------------------------------------------------------------------------
    // Row4 type methods
    // -------------------------------------------------------------------------

    @Override
    public Row4<UUID, String, String, OffsetDateTime> fieldsRow() {
        return (Row4) super.fieldsRow();
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Function)}.
     */
    public <U> SelectField<U> mapping(
            Function4<? super UUID, ? super String, ? super String, ? super OffsetDateTime, ? extends U> from) {
        return convertFrom(Records.mapping(from));
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Class,
     * Function)}.
     */
    public <U> SelectField<U> mapping(
            Class<U> toType,
            Function4<? super UUID, ? super String, ? super String, ? super OffsetDateTime, ? extends U> from) {
        return convertFrom(toType, Records.mapping(from));
    }
}
